package com.bjc.platform.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.bjc.platform.dao.GenericDao;
import com.bjc.platform.model.AdmDepartmentType;
import com.bjc.platform.repository.AdmDepartmentTypeRepo;
import com.bjc.platform.service.IAdmDepartmentTypeService;
import com.bjc.platform.service.impl.BaseServiceImpl;

@Service("admDepartmentTypeService")
public class AdmDepartmentTypeServiceImpl extends BaseServiceImpl implements
		IAdmDepartmentTypeService {

	@Autowired
	GenericDao genericDao;

	@Autowired
	@Qualifier("admDepartmentTypeRepo")
	private AdmDepartmentTypeRepo admDepartmentTypeRepo;

	@Override
	public List<AdmDepartmentType> query(String companyCode) {
		return admDepartmentTypeRepo.findByCompanyCode(companyCode);
	}

	@Override
	public List<AdmDepartmentType> queryManufacture(String companyCode) {
		return admDepartmentTypeRepo.findByCompanyCodeAndDivision(companyCode, "MANUFACTURE");
	}

	public AdmDepartmentType queryOne(Integer id) {
		return admDepartmentTypeRepo.findOne(id);
	}

	@Override
	public List<Map<String, Object>> queryDep(String company_code) {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT o.name , o.id FROM adm_org o"
				+ " LEFT JOIN adm_department_type d ON o.org_sub_type = d.id"
				+ " WHERE o.org_type = 'DEPARTMENT' AND d.division = 'MANUFACTURE'"
				+ " AND o.`code` = ?");
		return genericDao.queryBySqlToMap(sb.toString(),
				new String[] { company_code });
	}
}
